package com.github.wisdom.member.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ccssoft.m8.common.web.BaseController;
import com.github.wisdom.member.entity.MemnerSignEntity;
import com.github.wisdom.member.entity.queryEntity.PagedQueryMemnerSignEntity;
import com.github.wisdom.member.service.MemnerSignService;
import com.ccssoft.m8.common.ccssoft.modules.util.PageUtils;
import com.ccssoft.m8.common.ccssoft.modules.util.ReturnEntity;
import com.ccssoft.m8.common.ccssoft.modules.util.QueryEntityTools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 会员签到记录
 *
 * @author ybg
 * @email ybg101010@163.com
 * @date 2018-09-13 21:41:30
 */
@Api(value = "会员签到记录",description="会员签到记录")
@RestController
@RequestMapping("/member/memner/signs")
public class MemnerSignController extends BaseController{
    @Autowired
    private MemnerSignService<MemnerSignEntity> memnerSignService;
    
    private static final String OBJECT_CODE = "${baseObjectCode}";

    /**
     * 列表
     */
    @ApiOperation("列表")
    @GetMapping("")
    public ReturnEntity<PageUtils<MemnerSignEntity>> list(PagedQueryMemnerSignEntity memnerSign){
    	Map<String, Object> params = QueryEntityTools.beanToMap(memnerSign);
		PageUtils<MemnerSignEntity> page = memnerSignService.queryPage(params);
        return new ReturnEntity<PageUtils<MemnerSignEntity>>().ok(page);
    }
    
    /**
     * 列表(不分页)
     */
    @ApiOperation("列表(不分页)")
    @GetMapping("/nopage")
    public ReturnEntity<List<MemnerSignEntity>> list(MemnerSignEntity memnerSign){
    	Map<String, Object> columnMap = QueryEntityTools.beanToColumnMap(memnerSign);
		List<MemnerSignEntity> page = memnerSignService.selectByMap(columnMap);
        return new ReturnEntity<List<MemnerSignEntity>>().ok(page);
    }

    /**
     * 信息
     */
    @ApiOperation("信息")
    @GetMapping("/{id}")
    public ReturnEntity<MemnerSignEntity> info(@PathVariable("id") String id){
    	MemnerSignEntity memnerSign = memnerSignService.selectById(id);
		return new ReturnEntity<MemnerSignEntity>().ok(memnerSign);
    }

     /**
     * 创建
     */
    @ApiOperation("创建")
    @PostMapping("")
    public ReturnEntity<MemnerSignEntity> save(@RequestBody MemnerSignEntity memnerSign){
    	memnerSign.setId(getUUIDPrimaryKey());
		verifications(QueryEntityTools.beanToMap(memnerSign), OBJECT_CODE);
		memnerSignService.insert(memnerSign);
        return new ReturnEntity<MemnerSignEntity>().ok(memnerSign);
    }

     /**
     * 修改
     */
    @ApiOperation("修改")
    @PutMapping("/{id}")
    public ReturnEntity<MemnerSignEntity> update(@PathVariable("id") String id,@RequestBody MemnerSignEntity memnerSign){
		if (id == null || id == "") {
			return new ReturnEntity<MemnerSignEntity>().error("id不能为空");
		} else {
			if (id.equals(memnerSign.getId())) {
			verifications(QueryEntityTools.beanToMap(memnerSign), OBJECT_CODE);
			memnerSignService.updateById(memnerSign);
			return new ReturnEntity<MemnerSignEntity>().ok(memnerSign);
		} else {
			return new ReturnEntity<MemnerSignEntity>().error("id不匹配");
		}
						}
    }
    /**
     * 批量删除
     */
    @ApiOperation("批量删除")
    @DeleteMapping("/batch")
    public ReturnEntity delete(@RequestBody String[] ids){
		memnerSignService.deleteBatchIds(Arrays.asList(ids));
    	return new ReturnEntity().ok();
    }

   /**
	 * 删除
	 */
	@ApiOperation("删除")
	@DeleteMapping("/{id}")
    public ReturnEntity delete(@PathVariable("id") String id){
		memnerSignService.deleteById(id);
		return new ReturnEntity().ok();
    }

}
